package action;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


import bean.Book;
import bo.BookManagementBO;

public class GoListBookAction extends Action {

	public ActionForward execute(ActionMapping mapping, ActionForm form,
	        HttpServletRequest request, HttpServletResponse response)  {

		try {
			ArrayList<Book> bookList = new ArrayList<Book>();
			int numberOfPage;
			BookManagementBO bookManagementBO = new BookManagementBO();

				bookList = bookManagementBO.getAllBook(1); // Get Trainee List in page 1
				numberOfPage = bookManagementBO.getTotalBookPage(); // Get
																			  // total
																		  // pages
			// Set attributes for list page with pagination
			request.setAttribute("bookList", bookList);
			request.setAttribute("currentPage", 1);
			request.setAttribute("numberOfPage", numberOfPage);
			return mapping.findForward("listBook");
		
		} catch (Exception e) {
			System.out.println(e.getMessage());
			return mapping.findForward("error");
		}
	}
}
